Skip to content

Conversation

@gmazoyer
Copy link
Contributor

@gmazoyer gmazoyer commented Aug 7, 2025

Summary by CodeRabbit

  • New Features

    • Added a new CLI command to initialize an Infrahub repository with customizable templates.
    • Introduced support for NumberPool attributes in generated protocols.
  • Bug Fixes

    • Improved value lookup for flat notation keys, especially for single-cardinality relationships.
    • Fixed file ordering when loading from directories and ensured only valid YAML/JSON files are processed.
    • Enhanced error handling when loading files and during schema loading.
  • Documentation

    • Updated documentation to cover the new repository initialization command and its options.
  • Tests

    • Added tests for repository initialization, flat value extraction, relationship attributes, and YAML file loading errors.
  • Refactor

    • Reworked node attribute and relationship extraction for improved recursive flat key resolution.
    • Switched relationship fetching to use batch processing for efficiency.
  • Chores

    • Updated dependencies and project version.
    • Improved linting task to exclude node_modules in documentation.

Copilot AI and others added 30 commits June 30, 2025 07:22
…ng _init_relationships (#456)

* Add setting typename if it exists when calling _init_relationships on relationships that are already a RelatedNode

* small unit test update

* cover display_label and kind too

* add changelog

---------

Co-authored-by: Aaron McCarty <[email protected]>
…nsions (#463)

* Fix load_from_disk method

* Add unit test to cover file doesn't exist case

* Add changelog

* Add files to be ignored as part of the tests
* Update dependencies

Add init command

Add testing

changelog

Add docs

Add copier to all extras

update lock file

update lock file

update lock file

update lock file

* update lock file

* update lock file
* fix: improve cardinality many relationship fetch

Signed-off-by: Fatih Acar <[email protected]>
Add check for empty list of schema
Fix vale lint command to exclude node_modules directory
Create batch directly instead of using create_batch while fetching relationships
dgarros and others added 8 commits July 24, 2025 15:35
Merge stable into develop
…ort-to-protocols

add support for NumerPool attributes to protocols
This change moves the `get_flat_value` function to methods of the `InfrahubNode` and `InfrahubNodeSync` classes. This allows to handle traversing relationships of cardinality one using a flat notation in addition to attributes.

The `extract` method has also been moved as it needs to be async for regular nodes now.
@coderabbitai
Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

This update introduces new features, bug fixes, and enhancements across the SDK, CLI, and test suites. Notable changes include recursive flat key resolution in node classes, improved batch relationship fetching, a new CLI command for repository initialization, stricter YAML file handling, updated documentation, dependency additions, and expanded tests.

Changes

Cohort / File(s) Change Summary
Changelog and Release Notes
CHANGELOG.md, changelog/*
Added changelog entries for releases 1.13.3–1.13.5, new features, and bug fixes including batch handling, branch-aware counting, NumberPool protocol support, and flat notation fixes.
Repository Initialization Feature
infrahub_sdk/ctl/repository.py, docs/docs/infrahubctl/infrahubctl-repository.mdx, tests/unit/ctl/test_repository_app.py
Introduced infrahubctl repository init CLI command for initializing repositories from templates, with documentation and integration tests for local and remote templates.
Node Flat Key and Extraction Refactor
infrahub_sdk/node/node.py, infrahub_sdk/utils.py, infrahub_sdk/protocols_base.py, tests/unit/sdk/test_node.py, tests/unit/sdk/test_utils.py
Moved and enhanced get_flat_value and extract methods into node classes, supporting recursive flat key lookups for attributes/relationships; removed utility function and protocol method; updated and added targeted tests.
Relationship Batch Fetching
infrahub_sdk/node/relationship.py
Refactored relationship fetching to use batched filter queries by typename, replacing individual fetch calls, and added input validation.
Related Node Metadata
infrahub_sdk/node/related_node.py, tests/unit/sdk/test_node.py
Added kind property and metadata extraction to related nodes; expanded tests to verify new attributes.
YAML File Handling and Validation
infrahub_sdk/yaml.py, infrahub_sdk/ctl/utils.py, tests/unit/sdk/test_yaml.py
Improved recursive YAML directory loading, stricter file extension checks, explicit error handling for missing files/directories, and new test for non-existent folder error.
Schema File Payload Refactor
infrahub_sdk/ctl/schema.py
Changed schema handling to use payload attribute instead of content, updated type hints, and refined error display logic.
Client Batch and Count Handling
infrahub_sdk/client.py
Removed unused node instantiations in filters, ensured branch-aware count queries, and updated batch processing method calls.
Protocol Generator Constants
infrahub_sdk/protocols_generator/constants.py
Added "NumberPool" attribute kind mapping to protocol generator.
Project Configuration and Linting
pyproject.toml, tasks.py
Updated version to 1.13.5, added copier dependency, adjusted linting to exclude node_modules in docs.
Integration Test Enhancement
tests/integration/test_node.py
Added assertion to verify related node typename in relationships.

Sequence Diagram(s)

Repository Initialization Command

sequenceDiagram
    participant User
    participant CLI (infrahubctl)
    participant Copier
    participant FileSystem

    User->>CLI (infrahubctl): Run 'repository init' with directory, template, data, etc.
    CLI (infrahubctl)->>FileSystem: Check if template path exists
    CLI (infrahubctl)->>FileSystem: Load YAML data if provided
    CLI (infrahubctl)->>Copier: Run copy operation (async)
    Copier->>FileSystem: Copy template files to target directory
    Copier-->>CLI (infrahubctl): Return success or error
    CLI (infrahubctl)-->>User: Print result or error
Loading

Node Flat Key Extraction

sequenceDiagram
    participant Caller
    participant InfrahubNode
    participant RelatedNode
    participant RelationshipManager

    Caller->>InfrahubNode: get_flat_value("foo__bar__baz")
    InfrahubNode->>InfrahubNode: Traverse attribute "foo"
    alt Relationship (cardinality one)
        InfrahubNode->>RelationshipManager: fetch related node
        RelationshipManager->>RelatedNode: retrieve node data
        RelatedNode->>InfrahubNode: get_flat_value("baz")
    else Attribute
        InfrahubNode->>InfrahubNode: Traverse attribute "bar"
        InfrahubNode-->>Caller: Return value of "baz"
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • ajtmccarty
  • dgarros

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or Summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the type/documentation Improvements or additions to documentation label Aug 7, 2025
@codecov
Copy link

codecov bot commented Aug 7, 2025

Codecov Report

❌ Patch coverage is 79.84496% with 26 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/node/node.py 85.45% 8 Missing ⚠️
infrahub_sdk/ctl/repository.py 66.66% 6 Missing and 1 partial ⚠️
infrahub_sdk/ctl/schema.py 55.55% 3 Missing and 1 partial ⚠️
infrahub_sdk/node/relationship.py 80.95% 2 Missing and 2 partials ⚠️
infrahub_sdk/ctl/utils.py 0.00% 2 Missing and 1 partial ⚠️
@@                 Coverage Diff                  @@
##           infrahub-develop     #489      +/-   ##
====================================================
+ Coverage             70.92%   76.24%   +5.31%     
====================================================
  Files                    87      100      +13     
  Lines                  7879     9032    +1153     
  Branches               1527     1731     +204     
====================================================
+ Hits                   5588     6886    +1298     
+ Misses                 1897     1670     -227     
- Partials                394      476      +82     
Flag Coverage Δ
integration-tests 36.06% <19.37%> (+13.35%) ⬆️
python-3.10 49.28% <67.44%> (+4.04%) ⬆️
python-3.11 49.28% <67.44%> (+4.07%) ⬆️
python-3.12 49.25% <67.44%> (+4.04%) ⬆️
python-3.13 49.23% <67.44%> (+4.00%) ⬆️
python-3.9 47.97% <66.66%> (+3.85%) ⬆️
python-filler-3.12 24.57% <7.75%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/client.py 69.48% <100.00%> (+1.92%) ⬆️
infrahub_sdk/node/related_node.py 90.25% <100.00%> (ø)
infrahub_sdk/protocols_base.py 74.21% <ø> (-5.59%) ⬇️
infrahub_sdk/protocols_generator/constants.py 100.00% <ø> (ø)
infrahub_sdk/utils.py 85.11% <ø> (+5.20%) ⬆️
infrahub_sdk/yaml.py 84.54% <100.00%> (+6.06%) ⬆️
infrahub_sdk/ctl/utils.py 68.08% <0.00%> (+1.41%) ⬆️
infrahub_sdk/ctl/schema.py 55.83% <55.55%> (ø)
infrahub_sdk/node/relationship.py 72.41% <80.95%> (ø)
infrahub_sdk/ctl/repository.py 78.57% <66.66%> (-3.25%) ⬇️
... and 1 more

... and 18 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmazoyer gmazoyer marked this pull request as ready for review August 7, 2025 09:13
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
changelog/+add_numberpool_support_protocols.added.md (1)

1-1: Changelog style nitpick

For consistency with other entries, capitalise the first word and add a period:

Add support for NumberPool attributes in generated protocols.
infrahub_sdk/yaml.py (1)

123-124: Address the FIXME comment regarding JSON files

The comment indicates that .json support should be removed since this is specifically for YAML files. Consider creating a separate issue to address this technical debt.

Would you like me to create an issue to track the removal of JSON support from the YAML file loader?

infrahub_sdk/ctl/repository.py (1)

198-200: Consider using more specific exception types

The code uses generic Exception in except clauses. Consider catching more specific exceptions to handle different error scenarios appropriately:

  • For YAML loading: yaml.YAMLError, IOError, OSError
  • For copier execution: specific copier exceptions or OSError
-        except Exception as exc:
+        except (yaml.YAMLError, IOError, OSError) as exc:
             typer.echo(f"Error loading YAML file: {exc}", err=True)
-    except Exception as e:
+    except (OSError, RuntimeError) as e:
         typer.echo(f"Error running copier: {e}", err=True)

Also applies to: 216-218

infrahub_sdk/node/relationship.py (2)

165-166: Consider adding peer information to error message

The error message could be more informative by including which peer lacks the required fields.

-            if not peer.id or not peer.typename:
-                raise Error("Unable to fetch the peer, id and/or typename are not defined")
+            if not peer.id or not peer.typename:
+                raise Error(f"Unable to fetch the peer for relationship '{self.name}': id={peer.id}, typename={peer.typename}")

Also applies to: 288-289


181-182: Document the side effect of batch execution

The batch execution updates peers through the store as a side effect. Consider adding a comment to clarify this behavior for future maintainers.

+        # Execute batch to populate the store with peer data
         async for _ in batch.execute():
             pass

Also applies to: 305-306

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 021a378 and 0cde3c6.

⛔ Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (25)
  • CHANGELOG.md (1 hunks)
  • changelog/+add_numberpool_support_protocols.added.md (1 hunks)
  • changelog/+batch.fixed.md (1 hunks)
  • changelog/+branch-in-count.fixed.md (1 hunks)
  • changelog/466.added.md (1 hunks)
  • changelog/6882.fixed.md (1 hunks)
  • docs/docs/infrahubctl/infrahubctl-repository.mdx (2 hunks)
  • infrahub_sdk/client.py (5 hunks)
  • infrahub_sdk/ctl/repository.py (2 hunks)
  • infrahub_sdk/ctl/schema.py (6 hunks)
  • infrahub_sdk/ctl/utils.py (1 hunks)
  • infrahub_sdk/node/node.py (7 hunks)
  • infrahub_sdk/node/related_node.py (2 hunks)
  • infrahub_sdk/node/relationship.py (3 hunks)
  • infrahub_sdk/protocols_base.py (0 hunks)
  • infrahub_sdk/protocols_generator/constants.py (1 hunks)
  • infrahub_sdk/utils.py (0 hunks)
  • infrahub_sdk/yaml.py (1 hunks)
  • pyproject.toml (4 hunks)
  • tasks.py (1 hunks)
  • tests/integration/test_node.py (1 hunks)
  • tests/unit/ctl/test_repository_app.py (2 hunks)
  • tests/unit/sdk/test_node.py (5 hunks)
  • tests/unit/sdk/test_utils.py (0 hunks)
  • tests/unit/sdk/test_yaml.py (2 hunks)
💤 Files with no reviewable changes (3)
  • infrahub_sdk/utils.py
  • tests/unit/sdk/test_utils.py
  • infrahub_sdk/protocols_base.py
🧰 Additional context used
🧬 Code Graph Analysis (7)
infrahub_sdk/node/related_node.py (2)
infrahub_sdk/protocols_base.py (1)
  • get_kind (193-193)
infrahub_sdk/node/node.py (1)
  • get_kind (173-174)
tests/integration/test_node.py (1)
infrahub_sdk/node/related_node.py (3)
  • peer (213-214)
  • peer (260-261)
  • typename (117-120)
infrahub_sdk/node/relationship.py (4)
infrahub_sdk/batch.py (1)
  • InfrahubBatch (55-89)
infrahub_sdk/exceptions.py (1)
  • UninitializedError (156-157)
infrahub_sdk/types.py (1)
  • Order (71-72)
infrahub_sdk/node/related_node.py (4)
  • peer (213-214)
  • peer (260-261)
  • id (83-86)
  • typename (117-120)
infrahub_sdk/ctl/schema.py (2)
infrahub_sdk/schema/__init__.py (5)
  • validate (101-102)
  • load (287-299)
  • load (712-724)
  • check (321-335)
  • check (746-760)
infrahub_sdk/yaml.py (3)
  • data (147-150)
  • payload (168-169)
  • SchemaFile (166-169)
infrahub_sdk/node/node.py (6)
infrahub_sdk/utils.py (2)
  • compare_lists (124-135)
  • generate_short_id (30-32)
infrahub_sdk/node/attribute.py (2)
  • value (66-67)
  • value (70-72)
infrahub_sdk/protocols_base.py (7)
  • id (15-15)
  • hfid (18-18)
  • hfid (184-184)
  • typename (33-33)
  • display_label (30-30)
  • RelatedNode (44-44)
  • RelatedNodeSync (48-48)
infrahub_sdk/node/related_node.py (13)
  • id (83-86)
  • hfid (89-92)
  • typename (117-120)
  • kind (123-126)
  • display_label (111-114)
  • RelatedNode (182-226)
  • fetch (204-210)
  • fetch (251-257)
  • peer (213-214)
  • peer (260-261)
  • get (216-226)
  • get (263-273)
  • RelatedNodeSync (229-273)
infrahub_sdk/schema/main.py (3)
  • attribute_names (223-224)
  • get_relationship (187-191)
  • RelationshipCardinality (17-19)
infrahub_sdk/node/relationship.py (3)
  • fetch (148-182)
  • fetch (271-306)
  • RelationshipManagerSync (223-343)
tests/unit/sdk/test_node.py (2)
tests/unit/sdk/conftest.py (5)
  • mock_schema_query_01 (1824-1831)
  • clients (37-42)
  • location_schema (140-172)
  • location_data01 (375-412)
  • client (32-33)
infrahub_sdk/node/node.py (6)
  • InfrahubNode (452-1078)
  • get_flat_value (1031-1061)
  • get_flat_value (1657-1687)
  • InfrahubNodeSync (1081-1704)
  • extract (1063-1069)
  • extract (1689-1695)
infrahub_sdk/yaml.py (1)
infrahub_sdk/exceptions.py (1)
  • FileNotValidError (164-167)
🪛 LanguageTool
docs/docs/infrahubctl/infrahubctl-repository.mdx

[style] ~67-~67: To form a complete sentence, be sure to include a subject or ‘there’.
Context: ...Template to use for the new repository. Can be a local path or a git repository URL...

(MISSING_IT_THERE)

🔇 Additional comments (51)
infrahub_sdk/protocols_generator/constants.py (1)

25-25: Confirm downstream handling for newly-added 'NumberPool' mapping

Mapping the new attribute kind to "Integer" looks fine in isolation.
Please double-check that:

• Any validation or enum logic relying on ATTRIBUTE_KIND_MAP.keys() recognises 'NumberPool'.
• Protocol-generation tests cover this kind to catch template regressions.
• Serialisation/deserialisation code paths treat NumberPool consistently as integers (e.g. no string casting surprises).

If these items are already covered elsewhere, no further action needed.

changelog/+branch-in-count.fixed.md (1)

1-1: LGTM - Clear changelog entry

The changelog entry clearly describes the update to include branch parameters in count calls, ensuring branch-aware querying.

pyproject.toml (3)

3-3: Version update looks appropriate

The version bump from 1.13.2 to 1.13.5 aligns with the feature additions and fixes in this release.


48-48: Dependency addition for new repository init command

The addition of the copier dependency correctly supports the new infrahubctl repository init command functionality.


73-73: Proper inclusion in extras groups

The copier dependency is correctly included in both the ctl and all extras groups, ensuring it's available when needed.

Also applies to: 85-85

infrahub_sdk/yaml.py (3)

126-128: Excellent error handling improvement

The explicit path existence check with a meaningful error message using FileNotValidError significantly improves user experience when invalid paths are provided.


130-132: Good file extension filtering

The implementation correctly filters files by extension and silently skips irrelevant files, which is the appropriate behavior for a YAML loader.


134-137: Well-implemented recursive directory handling

The recursive approach with sorting ensures consistent processing order and proper handling of nested directory structures. The sorting by name provides predictable behavior.

changelog/+batch.fixed.md (1)

1-1: Clear description of batch handling improvement

The changelog entry accurately describes the change to create new batches during relationship fetching instead of reusing existing ones, which should improve performance and reliability.

changelog/466.added.md (1)

1-1: Comprehensive description of new repository init command

The changelog entry clearly describes the new infrahubctl repository init command and appropriately references the template repository it uses.

changelog/6882.fixed.md (1)

1-1: LGTM - Clear changelog entry

The changelog entry clearly describes the fix for flat notation value lookup with relationships of cardinality one.

tests/integration/test_node.py (1)

86-86: LGTM - Enhanced test coverage

Good addition to verify the typename attribute of related nodes, which aligns with the enhanced metadata handling introduced in this PR.

tasks.py (1)

204-204: LGTM - Sensible exclusion of node_modules

Good improvement to exclude node_modules directories from Vale linting, which avoids checking third-party documentation files.

infrahub_sdk/node/related_node.py (2)

42-42: LGTM - Proper initialization

The _kind attribute is properly initialized to None, following the pattern of other metadata attributes.


122-126: LGTM - Well-implemented kind property

The kind property follows the established pattern of delegating to the peer when available, otherwise returning the stored value. The implementation is consistent with other similar properties in this class.

tests/unit/sdk/test_yaml.py (3)

3-3: LGTM - Required import for exception testing

Appropriate addition of pytest import for the new exception testing functionality.


5-6: LGTM - Proper imports for new test

Good addition of the required imports for the new test case covering error handling scenarios.


51-54: LGTM - Good error handling test coverage

Excellent addition of a test case that verifies proper error handling when attempting to load YAML files from a non-existent directory. The test correctly uses pytest.raises and validates the error message content.

infrahub_sdk/ctl/utils.py (1)

190-192: LGTM! Good defensive programming.

The addition of an early exit when no valid files are found prevents unexpected behavior and provides clear feedback to users. The error message is informative and the exit code is appropriate.

CHANGELOG.md (1)

14-35: LGTM! Standard changelog documentation.

The changelog entries follow the established format and properly document the historical releases with clear descriptions and issue references.

infrahub_sdk/client.py (3)

827-827: Good addition of branch parameter to count method

The addition of the branch parameter to the count method ensures that count queries respect the branch context, which is essential for accurate counting in a branch-aware system.

Also applies to: 832-832, 849-849


832-832: Improved code clarity with keyword arguments

Using keyword arguments for process_page calls improves code readability and makes the parameter passing more explicit.

Also applies to: 849-849, 1997-1997, 2014-2014


1950-1950: Consistent branch parameter addition in sync client

The sync client implementation correctly mirrors the async client's changes by adding the branch parameter to the count method, maintaining consistency between both implementations.

Also applies to: 1992-1992

docs/docs/infrahubctl/infrahubctl-repository.mdx (1)

22-22: Well-documented new command

The documentation for the new init command is comprehensive and follows the existing documentation pattern consistently. All options are clearly described with appropriate defaults.

Also applies to: 51-73

infrahub_sdk/node/relationship.py (2)

163-182: Efficient batched fetching implementation

The refactoring from individual peer fetches to batched fetching by typename is a solid performance improvement. The use of Order(disable=True) further optimizes the queries.


293-293: Clear comment about batch creation difference

Good documentation explaining why the sync version doesn't need a new batch instance due to the absence of semaphore-based concurrency control.

infrahub_sdk/ctl/schema.py (8)

35-35: LGTM - Function signature updated for better type safety.

The type hint change from list[dict] to list[SchemaFile] improves type safety and accurately reflects that the function expects SchemaFile instances rather than raw dictionaries.


39-39: Good refactoring to use the payload property.

Using schema_file.payload instead of direct content access provides better encapsulation and ensures a dictionary is always returned (falling back to {} if content is None).


51-51: LGTM - Consistent type hint improvement.

The updated type hint correctly reflects that the function expects SchemaFile instances, maintaining consistency with other function signature updates in this file.


90-90: LGTM - Safe direct access after key existence check.

The change from response.get("errors") to response["errors"] is appropriate since line 89 already verifies the "errors" key exists in the response.


100-102: Consistent refactoring to use payload property.

The function signature update and switch to payload access maintain consistency with the broader refactoring in this file. The payload property provides safer access to schema data.


125-125: Consistent payload usage in schema loading.

The change to use item.payload maintains consistency with the refactoring throughout this file and ensures proper data access.


173-173: Consistent payload usage in schema checking.

The change to use item.payload aligns with the refactoring pattern and ensures consistent data access across schema operations.


176-176: Good defensive programming for None response handling.

Using response or {} safely handles the case where client.schema.check might return None as the second tuple element, preventing potential AttributeError when accessing response keys.

tests/unit/ctl/test_repository_app.py (4)

3-4: LGTM - Appropriate imports for new test functionality.

The addition of tempfile and Path imports supports the new test methods that need to create temporary directories and files for testing the repository init command.


8-8: LGTM - YAML import needed for test data handling.

The yaml import is required for the new tests that need to create and read YAML configuration files for the repository init command testing.


329-361: Well-structured integration test for repository init command.

The test properly uses context managers for resource cleanup, creates realistic test data, and verifies both the command execution and the expected output structure. The assertions cover the key aspects of the repository initialization functionality.

A few observations:

  • Good use of temporary files and directories for isolation
  • Proper verification of both the copied answers and the generated project structure
  • The removal of _src_path from copied answers is appropriate as it's an internal copier field

363-397: Comprehensive test for local template functionality.

This test effectively covers the local template scenario with:

  • Proper setup of a minimal copier template structure
  • Creation of Jinja template files for testing rendering
  • Verification of both command success and output correctness
  • Good use of temporary directories for test isolation

The test demonstrates thorough coverage of the template rendering workflow and validates that the generated content matches expectations.

tests/unit/sdk/test_node.py (4)

199-205: LGTM! Good test coverage expansion.

The additional parametrized test case appropriately tests relationship initialization with different metadata field formats (__typename vs kind/display_label), which aligns with the enhanced relationship node handling mentioned in the summary.


240-242: LGTM! Proper verification of relationship metadata.

These assertions correctly verify that relationship nodes now carry the additional metadata fields (typename, kind, display_label) as mentioned in the enhanced summary, ensuring the new functionality works as expected.


885-897: LGTM! Mock response properly simulates batched fetching.

The additional intermediate mock response (response2) with count but no edges correctly simulates the new batched relationship fetching behavior, ensuring tests cover the pagination scenarios mentioned in the summary.


963-2008: Excellent test coverage for new flat key resolution functionality.

Both test_get_flat_value and test_node_extract provide comprehensive testing of the new methods with proper:

  • Testing of different key formats and separators
  • Error handling for multi-cardinality relationships
  • Coverage of both async and sync variants
  • HTTP mocking that matches the new batched fetching behavior

The tests align well with the functionality described in the relevant code snippets from infrahub_sdk/node/node.py.

infrahub_sdk/node/node.py (9)

11-11: LGTM!

The removal of get_flat_value from the utils import is consistent with its reimplementation as a method within the node classes.


405-409: Good fix for handling zero values correctly.

The explicit is not None checks are more robust than falsiness checks, correctly handling cases where offset or limit is 0.


502-512: Clean refactoring using dictionary comprehension.

The dictionary comprehension efficiently includes only non-None values for the relationship data fields, making the code more concise and maintainable.


1031-1061: Well-implemented recursive flat value resolution.

The async get_flat_value method correctly handles both attributes and relationships with proper error handling and cardinality validation. The recursive approach for relationship traversal is appropriate.


1063-1069: Simple and effective extract method implementation.

The method correctly delegates to get_flat_value for each parameter, maintaining the async pattern throughout.


1131-1141: Consistent refactoring in sync class.

The dictionary comprehension in InfrahubNodeSync correctly mirrors the implementation in InfrahubNode, maintaining consistency between async and sync versions.


1528-1529: Good defensive programming with safer dictionary access.

Using .get() with None default prevents potential KeyError exceptions when accessing nested dictionary keys, improving robustness.

Also applies to: 1535-1536


1657-1687: Correct synchronous implementation of get_flat_value.

The synchronous version properly mirrors the async implementation, correctly handling both attributes and relationships without async/await.


1689-1695: Consistent synchronous extract implementation.

The method correctly mirrors the async version, maintaining consistency across the codebase.

@gmazoyer gmazoyer merged commit 760cf3a into infrahub-develop Aug 7, 2025
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.